package sector.soda.states;

import com.jme3.app.Application;
import com.jme3.app.state.AppStateManager;
import com.jme3.niftygui.NiftyJmeDisplay;
import de.lessvoid.nifty.Nifty;
import java.util.logging.Level;
import sector.soda.input.MainMenuController;

/**
 *
 * @author cheesecake
 */
public class MenuState extends BaseGameState {
    
    private Nifty nifty;    
    private Application app;

    public MenuState() {
        logger.log(Level.INFO, "MenuState constructor");
    }

    @Override
    public void initialize(AppStateManager stateManager, Application app) {
        logger.log(Level.INFO, "MenuState initialize");
        
        initialized = true;

        this.app = app;
        
        setupScene();
    }

    private void setupScene() {
        logger.log(Level.INFO, "MenuState setupScene");
        
        app.getGuiViewPort().clearScenes();
        app.getInputManager().setCursorVisible(true);

        /* TODO: Needed to add the nifty-1.2.jar to our project to
         * get the font in the xml to work. */
        NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(
                app.getAssetManager(),
                app.getInputManager(),
                app.getAudioRenderer(),
                app.getGuiViewPort());

        nifty = niftyDisplay.getNifty();
        nifty.fromXml("Interface/mainmenu.xml", "start", new MainMenuController(app));

        app.getGuiViewPort().addProcessor(niftyDisplay);
    }
    
    @Override
    public void cleanup() {
        logger.log(Level.INFO, "MenuState cleanup");
        
        initialized = false; 
        
        app.getGuiViewPort().clearScenes();
        app.getInputManager().setCursorVisible(false);
        
        nifty.exit();
    }
}
